package cn.iocoder.yudao.module.distm.controller.app.schedulerecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.distm.controller.app.schedulerecord.vo.AppDeliveryPageReqVO;
import cn.iocoder.yudao.module.distm.controller.app.schedulerecord.vo.AppScheduleRecordPageReqVO;
import cn.iocoder.yudao.module.distm.controller.app.schedulerecord.vo.AppScheduleRecordRespVO;
import cn.iocoder.yudao.module.distm.controller.app.schedulerecord.vo.AppScheduleRecordSaveReqVO;
import cn.iocoder.yudao.module.distm.dal.dataobject.schedule.ScheduleRecordDO;
import cn.iocoder.yudao.module.distm.dal.dataobject.schedule.ScheduleRecordHistoryDO;
import cn.iocoder.yudao.module.distm.service.schedule.ScheduleRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 配送管理-调度生产记录")
@RestController
@RequestMapping("/pplan/distm/schedule-record")
@Validated
public class AppScheduleRecordController {

    @Resource
    private ScheduleRecordService scheduleRecordService;


    @PutMapping("/update")
    @Operation(summary = "更新配送管理-调度生产记录")
    public CommonResult<Boolean> updateScheduleRecord(@Valid @RequestBody AppScheduleRecordSaveReqVO updateReqVO) {
        scheduleRecordService.appUpdateScheduleRecord(updateReqVO);
        return success(true);
    }


    @GetMapping("/get")
    @Operation(summary = "获得配送管理-调度生产记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppScheduleRecordRespVO> getScheduleRecord(@RequestParam("id") Long id) {
        ScheduleRecordDO scheduleRecord = scheduleRecordService.appGetScheduleRecord(id);
        return success(BeanUtils.toBean(scheduleRecord, AppScheduleRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得配送管理-调度生产记录分页")
    public CommonResult<PageResult<AppScheduleRecordRespVO>> getScheduleRecordPage(@Valid AppScheduleRecordPageReqVO pageReqVO) {
        PageResult<ScheduleRecordDO> pageResult = scheduleRecordService.appGetScheduleRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppScheduleRecordRespVO.class));
    }

    @GetMapping("today/page")
    @Operation(summary = "获得今日配送分页")
    public CommonResult<PageResult<AppScheduleRecordRespVO>> getTodayScheduleRecordPage(@Valid AppDeliveryPageReqVO pageReqVO) {
        PageResult<ScheduleRecordDO> pageResult = scheduleRecordService.appTodayScheduleRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppScheduleRecordRespVO.class));
    }

    @GetMapping("history/page")
    @Operation(summary = "获得配送管理历史记录分页")
    public CommonResult<PageResult<AppScheduleRecordRespVO>> getHistoryScheduleRecordPage(@Valid AppDeliveryPageReqVO pageReqVO) {
        PageResult<ScheduleRecordHistoryDO> pageResult = scheduleRecordService.appHistoryScheduleRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppScheduleRecordRespVO.class));
    }


}